use salvo::prelude::*;
use tracing;


#[derive(Default)]
pub struct WebTransportSpan;
#[async_trait]
impl Handler for WebTransportSpan {
    async fn handle(
        &self,
        req: &mut Request,
        depot: &mut Depot,
        res: &mut Response,
        ctrl: &mut FlowCtrl,
    ) {
        let client_addr = req.remote_addr().to_string();
        let id = req.param::<i64>("id").unwrap();

        // TODO: 此处要判断{id}合法性

        // 创建包含Stage/Client信息的span
        let span = tracing::info_span!(
            "wt",
            id = %id,
            client = %client_addr,
        );
        let _guard = span.enter();
        ctrl.call_next(req, depot, res).await;
    }
}